<template>
  <div id="mine-achievement">
    <achievement
      v-if="infoReady"
      :headers="headers"
      :lists="lists"
      attrOneName="order_num"
      attrTwoName="amount"></achievement>
  </div>
</template>

<script>
  import Achievement from '../comp/achievement.vue';
  export default {
    name: "mine-achievement",
    components: {
      Achievement
    },
    data() {
      return {
        headers: [
          '订单号',
          '订单业绩'
        ],
        lists: [
          {
            text: '全部',
            contents: [], // 根据后台接口数据格式 order_num、amount
          },
          {
            text: '本日',
            contents: [],
          },
          {
            text: '本月',
            contents: [],
          },
          {
            text: '本年',
            contents: [],
          }
        ],
        infoReady: false
      }
    },
    methods: {
      getAchievementList(type) {
        this.$http.post({
          api: this.$api.USER_ACHIEVEMENT_DETAIL,
          params: {
            user_id: localStorage.getItem('id'),
            type: type + 1 // 四种类型分别是 1 2 3 4 (not start from 0)
          },
          success: (res) => {
            this.lists[type].contents = res.data.data;
          }
        })
      }
    },
    created() {
      for (let i = 0; i < this.lists.length; i++) {
        this.getAchievementList(i);

        if (i === 3) {
          this.infoReady = true;
        }
      }
    }
  }
</script>

<style scoped lang="scss"></style>
